<template>
  <view class="page_diy_table page_class_information_table" :style="{ paddingTop: vuex_custom_bar_height + 'px' }">
    <tn-nav-bar>班级信息列表</tn-nav-bar>
    <view class="page-list" id="page_diy_table">
      <!-- 筛选模块(开始) -->
      <view class="search-wrap">
        <!-- 搜索栏 -->
        <uni-forms :modelValue="query" labelWidth="70px">
            <uni-forms-item label="班级名称" name="class_name">
                <uni-easyinput type="text" v-model="query.class_name" placeholder="班级名称" />
              </uni-forms-item>
                  <uni-forms-item label="教师姓名" name="teachers_name">
                <uni-easyinput type="text" v-model="query.teachers_name" placeholder="教师姓名" />
              </uni-forms-item>
                </uni-forms>
        <!-- /搜索栏 -->
        <view class="search-btn-wrap">
          <view class="me-btn btn-reset" @click="reset()"> 重置 </view>
          <view class="me-btn btn-search" @click="search_()"> 查询 </view>
        </view>
		<view class="toolbar">
				  <view width="100%" class="me-btn btn-add" @click="$navTo('/pagesC/class_information/view?')" v-if="$check_action('/class_information/table', 'add') || $check_action('/class_information/view', 'add')">添加</view>
				</view>
      </view>
      <!-- 列表 -->
      <view class="list-wrap-row">
        <view v-for="(o, i) in list" :key="i" class="list-item">
          <view class="item-row " v-if="1 && $check_field('get','class_name')">
            <view class="label" v-if="true">
              <span>班级名称</span>
            </view>
              <view class="value">
              <span>{{ o['class_name'] }}</span>
            </view>
            </view>
          <view class="item-row " v-if="1 && $check_field('get','class_major')">
            <view class="label" v-if="true">
              <span>班级专业</span>
            </view>
              <view class="value">
              <span>{{ o['class_major'] }}</span>
            </view>
            </view>
          <view class="item-row " v-if="0 && $check_field('get','class_director')">
            <view class="label" v-if="true">
              <span>班级主任</span>
            </view>
              <view class="value">
              <span>{{ get_user_class_director(o['class_director']) }}</span>
            </view>
            </view>
          <view class="item-row " v-if="1 && $check_field('get','teachers_name')">
            <view class="label" v-if="true">
              <span>教师姓名</span>
            </view>
              <view class="value">
              <span>{{ o['teachers_name'] }}</span>
            </view>
            </view>
          <view class="item-row " v-if="0 && $check_field('get','class_size')">
            <view class="label" v-if="true">
              <span>班级人数</span>
            </view>
              <view class="value">
              <span>{{ o['class_size'] }}</span>
            </view>
            </view>
          <!-- <view class="item-row " v-if="0 && $check_field('get','classroom_location')">
            <view class="label" v-if="true">
              <span>教室位置</span>
            </view>
              <view class="value">
              <span>{{ o['classroom_location'] }}</span>
            </view>
            </view> -->
          <view class="item-row " v-if="0 && $check_field('get','class_details')">
            <view class="label" v-if="true">
              <span>班级详情</span>
            </view>
              <view class="value">
              <span>{{ o['class_details'] }}</span>
            </view>
            </view>
          <view class="content">
          </view>
          <view class="operate-bar">
            <view width="100%" class="me-btn btn-delete" @click="delInfo(i)"
                  v-if="$check_action('/class_information/table', 'del') || $check_action('/class_information/view', 'del')">
              删除
            </view>
            <view width="100%" class="me-btn btn-info" @click="$navTo('/pagesC/class_information/view?' + field + '=' + o[field])"
                  v-if="$check_action('/class_information/table', 'set') || $check_action('/class_information/view', 'set') || $check_action('/class_information/view', 'get')">
              详情
            </view>
          </view>
        </view>
      </view>
      <!-- /列表 -->
      <!-- 分页器 -->
      <uni-pagination
        class="pager"
        show-icon="true"
        :total="count"
        :pageSize="query.size"
        :current="query.page"
        @change="page_change"
      ></uni-pagination>
      <!-- /分页器 -->
    </view>
  </view>
</template>
<script>
import mixin from '@/libs/mixins/page.js';

export default {
  mixins: [mixin],
  data() {
    return {
      // 获取数据地址
      url_get_list: '~/api/class_information/get_list?like=0',
      url_del: '~/api/class_information/del',

      // 字段ID
      field: 'class_information_id',

      // 查询
      query: {
        size: 7,
        page: 1,
              class_name: "",
                        teachers_name: "",
                    login_time: '',
        create_time: '',
      },

      // 数据
      list: [],
                          // 用户列表
      list_user_class_director: [],
                      };
  },
  methods: {
    search_() {
      this.query.page = 1;
      this.get_list();
    },
    /**
     * 重置
     */
    reset: function reset() {
      uni.clear(this.query);
      uni.push(this.query, this.config);
      this.get_list();
    },
    get_list_before(param){
      var user_group = this.user.user_group;
      if(user_group != "管理员"){
          switch(user_group){
                                        case "教师用户":
            param["class_director"] = this.user.user_id;
            break;
                                                          }
        }
      return param;
    },
    delInfo(v) {
      let _this = this;
      uni.showModal({
        title: '删除',
        content: '此操作将永久删除该文件, 是否继续?',
        success: function (res) {
          if (res.confirm) {
            let list = [v];
            _this.delAll(list);
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        },
      });
    },
                      /**
     * 获取教师用户用户列表
     */
    async get_list_user_class_director() {
      var json = await this.$get("~/api/user/get_list?user_group=教师用户");
      if(json.result && json.result.list){
        this.list_user_class_director = json.result.list;
      }
      else if(json.error){
        console.error(json.error);
      }
    },

    get_user_class_director(id){
      let obj = this.list_user_class_director;
      let ret = "";
      for(let i=0;i<obj.length;i++){
        if(obj[i].user_id==id){
          ret = obj[i].nickname+"-"+obj[i].username;
        }
      }
      return ret;
    },
                            },
  created() {
                    this.get_list_user_class_director();
                    },
};
</script>

<style lang="scss" scoped>
  @import '@/styles/pagesC/index.scss';
</style>